using UnityEngine;

public class Enemy_AutoShotSample : Enemy
{
    float time = 0;
    public float shotTime = 3;
    public Bullet bullet;
    public float distance;
    [Tooltip("Disable")]
    public float dis;

    protected override void OnStart(){
        targetPlayer = GameManager.instance.player;
    }

    protected override void OnProcess(){
        time += processTime;
        Vector2 shotToward = Vector2.zero;
        dis = 0;
        if(targetPlayer){
            shotToward = targetPlayer.transform.position - transform.position;
            dis = shotToward.magnitude;
        }
        if(dis > 0){
            if(time >= shotTime){
                if(bullet)
                    Bullet.CreatBullet(bullet.gameObject, this, shotToward, 8);
                time = 0;
            }
            float d = dis - distance;
            if(Mathf.Abs(d) > 0.5f){
                Move(d * shotToward, speed);
            }else{
                Move(Vector2.zero, speed);
            }
        }
    }
}
